<script lang="ts" setup>
import { ref, reactive } from "vue";
interface PostDetail {
  Club?: string;
  UserId: number;
  avatarUrl: string;
  clubId?: string;
  clubName?: null;
  commentNums: number;
  content: string;
  createdAt: string;
  date: string;
  id: number;
  imgUrls?: string[];
  likeNums: number;
  statu: number;
  teacherId?: number;
  title?: string;
  type: string;
  updatedAt: string;
  username: string;
}
const props = withDefaults(
  defineProps<{
    data: PostDetail;
  }>(),
  {
    data: () => ({
      Club: "",
      UserId: 0,
      avatarUrl: "",
      clubId: "",
      clubName: null,
      commentNums: 0,
      content: "",
      createdAt: "",
      date: "",
      id: 0,
      imgUrls: [],
      likeNums: 0,
      statu: 0,
      teacherId: 0,
      title: "",
      type: "",
      updatedAt: "",
      username: "",
    }),
  }
);
//---
const dialogVisible = ref<boolean>(false);
const open = (): void => {
  dialogVisible.value = true;
};
const close = (): void => {
  dialogVisible.value = false;
}
defineExpose({
  open,
  close
});
//---
interface StatusItem {
  text: string;
  color: string;
}
const statusItems: StatusItem[] = reactive([
  {
    text: "审核中",
    color: "#e6a23c",
  },
  {
    text: "已通过",
    color: "#67c23a",
  },
  {
    text: "未通过",
    color: "#f56c6c",
  },
  {
    text: "社团老师审核中",
    color: "#e6a23c",
  },
]);
</script>
<template>
  <el-dialog
    v-model="dialogVisible"
    width="800"
    style="
      overflow-y: scroll;
      overflow-x: hidden;
      min-height: 40vh;
      min-width: 45vw;
      padding: 10px;
    "
    :show-close="true"
  >
    <div class="bgimg">
      <img src="../../../static/image/logo.png" alt="" />
    </div>
    <div class="userInf">
      <div class="userAvatar">
        <img :src="data.avatarUrl" alt="" />
      </div>
      <div style="height: 100%">
        <div class="userName">{{ data.username }}</div>
        <div class="userId">ID:{{ data.UserId }}</div>
      </div>
    </div>
    <div class="content">
      <div class="contentItem">
        <div class="key">帖子ID:</div>
        <div class="value">{{ data.id }}</div>
      </div>
      <div class="contentItem">
        <div class="key">帖子类型:</div>
        <div class="value">{{ data.type }}</div>
      </div>
      <div class="contentItem" v-if="data.title">
        <div class="key">帖子标题:</div>
        <div class="value">{{ data.title }}</div>
      </div>
      <div class="contentItem">
        <div class="key">帖子内容:</div>
        <div class="value">{{ data.content }}</div>
      </div>
      <div class="contentItem" v-if="data.clubName">
        <div class="key">所属社团:</div>
        <div class="value">{{ data.clubName }} (ID:{{ data.clubId }})</div>
      </div>
      <div class="contentItem">
        <div class="key">发布时间:</div>
        <div class="value">{{ data.date }}</div>
      </div>
      <div class="contentItem">
        <div class="key">审核状态:</div>
        <div class="value" :style="`color:${statusItems[data.statu]?.color}`">
          {{ statusItems[data.statu]?.text }}
        </div>
      </div>
    </div>
    <div class="imgList" v-if="data.imgUrls?.length">
      <img :src="url" v-for="url in data.imgUrls" :key="url" />
    </div>
    <template #footer>
      <div class="dialog-footer">
        <slot></slot>
      </div>
    </template>
  </el-dialog>
</template>
<style lang="scss" scoped>
.bgimg {
  height: 280px;
  width: 280px;
  position: absolute;
  right: 7px;
  top: 30px;
  border-radius: 50%;
  overflow: hidden;
  z-index: 2;

  &:before {
    content: "";
    display: block;
    height: 280px;
    width: 280px;
    background-color: rgba(255, 255, 255, 0.9999);
    opacity: 0.6;
    margin-bottom: -280px;
    border-radius: 50%;
  }

  img {
    height: 100%;
    width: 100%;
  }
}

.userInf {
  display: flex;
  align-items: center;
  position: relative;
  width: 100%;
  margin-left: 20px;

  &:after {
    content: "";
    display: block;
    height: 1px;
    width: 100%;
    background-color: #ebebeb;
    position: absolute;
    bottom: -10px;
    left: 10px;
    z-index: 1;
  }

  .userAvatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: hidden;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .userName {
    margin-left: 10px;
    font-size: 16px;
    font-weight: 600;
  }

  .userId {
    margin-left: 10px;
    font-size: 12px;
    color: #999;
    margin-top: 5px;
  }
}

.conBth {
  margin-left: 87%;
  transform: translateY(-25%);
}

.content {
  margin-top: 30px;
  margin-left: 20px;
  width: 100%;

  .contentItem {
    display: flex;
    width: 75%;
    min-height: 40px;
    font-size: 16px;
    margin: 10px 0;

    .key {
      color: #ababab;
      width: 20%;
    }

    .value {
      width: 65%;
      color: black;
      z-index: 3;
    }
  }
}

.imgList {
  margin-top: 20px;
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  min-height: 100px;
  display: grid;
  margin-left: 20px;
  grid-template-columns: repeat(5, 1fr);

  img {
    width: 145px;
    height: 145px;
  }
}
</style>
